
Page({

    /**
     * 页面的初始数据
     */
    data: {
        header: '',
        tag1_content: [],
        tag2_content: [],
        tag3_content: [],
        tag4_content: [],
        tag5_content: [],
        tag6_content: [],
        currentTagContent: [],
    },

  
    onLoad: function (options) {
        const name = options.name;
        var that = this;
        if (name === '幼儿唐诗大全') {
            that.getTagContent('tag1');
            that.setData({
            header: '幼儿唐诗大全',
           content: that.data.tag1_content
            })
        }
      

        else if (name === '小学必背古诗') {
            // this.getTagContent('tag2');
          that.setData({
            header: '小学必背古诗',
            content: that.data.tag2_content
          })
        } else if (name === '初中必背古诗') {
            that.getTagContent('tag3');
            that.setData({
              header: '初中必背古诗',
              content: that.data.tag3_content
            })
          } else if (name === '高中必背古诗') {
            that.getTagContent('tag4');
            that.setData({
              header: '高中必背古诗',
              content: that.data.tag4_content
            })
          } else if (name === '初中必背文言文') {
            that.getTagContent('tag5');
            that.setData({
              header: '初中必背文言文',
              content: that.data.tag5_content
            })
          } else if (name === '高中必背文言文') {
            that.getTagContent('tag6');
            that.setData({
              header: '高中必背文言文',
              content: that.data.tag6_content
            })
          } 
          
    },
 // 获取指定标签类别的内容
 getTagContent: function (tag) {
    var that = this;
    // var poemLength = 10; // 假设你要给poemLength赋一个初始值
    wx.request({
      url: 'http://127.0.0.1:5000/api/' + tag,
      success: function (res) {
        // console.log('Response:', res);
        that.setData({
          [tag + '_content']: res.data ,// 成功获取内容后将其保存在对应标签的 content 属性中
        });

      },
      fail: function (err) {
        console.error('Failed to fetch data:', err); // 检查请求失败的情况
    }
    });
  },
  

   
})